<template>
  <el-dialog :v-model="showDialog" title="批量分配宿舍" width="30%">
    <el-form ref="form">
      <el-form-item label="选择宿舍楼">
        <el-select v-model="selectedBuilding" placeholder="请选择宿舍楼">
          <el-option v-for="building in buildings" :key="building.id" :label="building.name" :value="building.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择宿舍号">
        <el-select v-model="selectedDorm" placeholder="请选择宿舍号">
          <el-option v-for="dorm in dorms" :key="dorm.id" :label="dorm.number" :value="dorm.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="assignDorm">确定</el-button>
    </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "bulk-assign-dorm",
  props: {
    selectedStudents: {
      type: Array,
      default: () => []
    },
    value: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {
      showDialog: false,
      NewselectedStudents: [],
      selectedBuilding: null,
      selectedDorm: null,
      buildings: [
        { id: 1, name: "宿舍楼A" },
        { id: 2, name: "宿舍楼B" },
        { id: 3, name: "宿舍楼C" }
      ],
      dorms: [
        { id: 1, number: "101" },
        { id: 2, number: "102" },
        { id: 3, number: "103" }
      ]
    };
  },
  methods: {

    cancel() {
      console.log("cancel");
      this.emitShowBulkAssianEvent()
      console.log(this.selectedStudents);
      this.NewselectedStudents=this.selectedStudents.map(item=>item.SNO)
      console.log(this.NewselectedStudents);
      // console.log(this.showDialog)
      console.log(this.selectedBuilding);

    },
    emitShowBulkAssianEvent() {
      this.$emit('showBulkAssianEvent');
    },
    assignDorm() {
      if (!this.selectedBuilding || !this.selectedDorm) {
        this.$message.error("请选择宿舍楼和宿舍号");
        return;
      }

      // 执行分配宿舍的操作，根据实际需求进行调整

      this.$message.success("宿舍分配成功");
      // this.cancel();
    }
  }
};
</script>
